home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / sockd.zip / sockdrep.cmd < prev   
OS/2 REXX Batch file  |  1997-03-12  |  6KB  |  215 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /*  sockdrep.cmd :  A sample Rexx program to report sockd activities      */
  4. /*                                                                        */
  5. /*   This program reads the archived sockdlog.XXX files in the current    */
  6. /*  directory and writes the activity report to the screen.               */
  7. /*                                                                        */
  8. /*  Usage : enter "sockdrep" without parameter                            */
  9. /*                                                                        */
  10. /*                                            Philippe Gillain  March 1997*/
  11. /**************************************************************************/
  12.  
  13. '@echo off'
  14. trace off
  15.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  16.   call SysLoadFuncs
  17.  
  18. parse upper arg Parm_field;
  19. if Parm_field = '?' | Parm_field = 'HELP' then do
  20.    call usage
  21.    exit
  22.    end
  23.  
  24.  numeric digits 15
  25.  numeric form  engineering
  26.  numeric fuzz  0
  27.  
  28.   host_nb = 0
  29.  
  30.   dial_up_Nb  = 0
  31.   dial_up_HH  = 0
  32.   dial_up_MM  = 0
  33.   dial_up_start_day  = 0
  34.   dial_up_start_time = " "
  35.   dial_up_end_day    = 0
  36.   dial_up_end_time   = " "
  37.   dial_up_delay      = 0
  38.  
  39.  
  40. /*------------------------------------------------------------------
  41.  * read the parameters
  42.  *------------------------------------------------------------------*/
  43. /*  parse arg file_name line_name line_name2 . */
  44.  
  45. file_name = "sockdlog.001"
  46. start_time = "-"
  47. start_day  = " "
  48. start_month = " "
  49. end_time = " "
  50. end_day  = " "
  51. end_month = " "
  52. cur_hour = 0
  53. i = 0
  54. j = 0
  55. k = 0
  56.  
  57. call SysFileTree 'sockdlog.*', 'filename', 'F'
  58.  
  59. do i = 1 to filename.0
  60.   file_name = word(filename.i,5)
  61.   if lines(file_name) > 0 then do
  62.     work_line = linein(file_name)
  63.     if word(work_line,1) = "sockdlog" then do
  64.       if start_time = "-" then do
  65.          start_month = word(work_line,4)
  66.          start_day   = word(work_line,5)
  67.          start_time  = word(work_line,6)
  68.          end
  69.       do while lines(file_name) > 0
  70.         work_line = linein(file_name)
  71.         word1 = word(work_line,1)
  72.         SELECT
  73.           WHEN word1 = "dial-up" THEN call DialUp;
  74.           WHEN word1 = "session" THEN call Session;
  75.           WHEN word1 = "error" THEN call ErrorRep;
  76.           WHEN word1 = "sockdlog" THEN do;
  77.              end_month = word(work_line,4)
  78.              end_day   = word(work_line,5)
  79.              end_time  = word(work_line,6)
  80.              end;
  81.           OTHERWISE
  82.         END
  83.       end
  84.     end
  85.   end
  86. end
  87.  
  88. say 'Report from ' || start_month || " " || start_day || " " || start_time || " to " ,
  89.                    || end_month || " " || end_day || " " || end_time
  90. say ' '
  91. say 'Number of dial-up sessions ' || dial_up_Nb
  92. say 'Total dial-up connection time ' || RIGHT(dial_up_HH,5,' ') || ":" ,
  93.                                      || RIGHT(dial_up_MM,2,'0') || " hours"
  94. say ' '
  95. say ' depress  ENTER to continue '
  96. Pull answer .
  97. call SysCls
  98. say ' '
  99. say ' Destination                    Port   Session Nb    Bytes Sent   Bytes Rcvd'
  100. say ' '
  101.  
  102.   j = 0
  103.   do i = 1 to host_nb
  104.     j = j + 1
  105.     say  LEFT(name.i,30) || ' ' || RIGHT(port.i,5,' ') || '     ' ,
  106.          RIGHT(session_nb.i,6,' ') || '   ' || RIGHT(bytin.i,12,' ') ,
  107.          || ' ' || RIGHT(bytout.i,12,' ')
  108.     if j > 16 then do
  109.        say ' '
  110.        say ' depress  ENTER to continue '
  111.        j = 0
  112.        Pull answer .
  113.        call SysCls
  114.        say ' '
  115.        say ' Destination                    Port   Session Nb    Bytes Sent   Bytes Rcvd'
  116.        say ' '
  117.        end
  118.     end
  119.  
  120. exit
  121.  
  122. DialUp:
  123.  if word(work_line,4) = "established" then do
  124.     dial_up_start_day  = word(work_line,7)
  125.     dial_up_start_time = word(work_line,8)
  126.     dial_up_delay = 0
  127.     end
  128.  else
  129.  if word(work_line,4) = "closed" then do
  130.     dial_up_end_day  = word(work_line,7)
  131.     dial_up_end_time = word(work_line,8)
  132.     if dial_up_end_day = dial_up_start_day then do
  133.        HH1 = SUBSTR(dial_up_start_time,1,2)
  134.        MM1 = SUBSTR(dial_up_start_time,4,2)
  135.        HH2 = SUBSTR(dial_up_end_time,1,2)
  136.        MM2 = SUBSTR(dial_up_end_time,4,2)
  137.        if MM2 < MM1 then do
  138.          MM2 = MM2 + 60
  139.          HH2 = HH2 -1
  140.          end
  141.        dial_up_Nb  = dial_up_Nb + 1
  142.        dial_up_HH  = dial_up_HH + HH2 - HH1
  143.        dial_up_MM  = dial_up_MM + MM2 - MM1
  144.        if dial_up_MM > 59 then do
  145.           dial_up_HH = dial_up_HH + 1
  146.           dial_up_MM = dial_up_MM - 60
  147.           end
  148.        end
  149.     end
  150.  RETURN
  151.  
  152. Session:
  153.   host_name   = word(work_line,11)
  154.   word1   = word(work_line,12)
  155.   j = LENGTH(word1)
  156.   if j > 7 then do
  157.     host_port = SUBSTR(word1,7,(j-7))
  158.     end
  159.   else host_port = 0
  160.   word2   = word(work_line,13)
  161.   k = LENGTH(word2)
  162.   if k > 4 then do
  163.      word3 = SUBSTR(word2,5,k)
  164.      l = pos('/',word3)
  165.      m = LENGTH(word3)
  166.      n = l - 1
  167.      word4  = SUBSTR(word3,1,n)
  168.      host_in  = word4
  169.      n = m -l
  170.      l = l + 1
  171.      word4  = SUBSTR(word3,l,n)
  172.      host_out = word4
  173.     end
  174.   else do
  175.     host_in  = 0
  176.     host_out = 0
  177.     end
  178.   not_found = 'Y'
  179.   do k = 1 to host_nb
  180.     if (name.k = host_name) & (port.k = host_port) then do
  181.       session_nb.k = session_nb.k + 1
  182.       bytin.k      = bytin.k  + strip(host_in)
  183.       bytout.k     = bytout.k + strip(host_out)
  184.       not_found = 'N'
  185.       k = host_nb
  186.       end
  187.     end
  188.   if not_found = 'Y' then do
  189.     host_nb = host_nb + 1
  190.     name.host_nb  = host_name
  191.     port.host_nb  = host_port
  192.     session_nb.host_nb  = 1
  193.     bytin.host_nb       = strip(host_in)
  194.     bytout.host_nb      = strip(host_out)
  195.     end
  196.  RETURN
  197.  
  198. ErrorRep:
  199.  if word(work_line,1) = "refused" then do
  200.    say work_line
  201.    end
  202.  RETURN
  203.  
  204. /*------------------------------------------------------------------
  205.  * some simple help
  206.  *------------------------------------------------------------------*/
  207. Usage: procedure
  208.  
  209.    say " "
  210.    say "usage : "
  211.    say "      start sockrep in the directory containing the sockdlog files "
  212.    say " "
  213.  
  214.    exit
  215.